import { PostRequest, PutRequest } from '@/utils/request'
import type { Response } from '@/utils/request'

export type UnReadModel = {
  appliance: boolean
  system: boolean
}
export type Message = {
  id: number
  haId: string
  unread: boolean
  messageTitle: string
  messageContent: string
  messageLink: string
  sendTime: string
  sendTimeByDateDesc: string
  sendTimeByTimeDesc: string
  canClick: boolean
}

export type messageByHaId = {
  haId: string
  type: string
  vib: string
  name: string
  image: string
  unread: boolean
  message: Message[]
}

export type DeviceMessageCenter = {
  unread: UnReadModel
  messageByHaId: messageByHaId[]
}

export type SystemMessageCenter = {
  unread: UnReadModel
  message: Message[]
}

export type DeviceMessageModel = {
  type: string
  snTicket: string
  sn: string
  modelId: string
}
/**
 * 获取设备消息列表
 * @returns
 */
export function getDeviceMessageList(page: number, pageSize: number): Promise<Response<DeviceMessageCenter>> {
  return PostRequest('/api/user/message/list', {
    type: 'appliance',
    page: page,
    pageSize: pageSize,
  })
}

/**
 * 获取系统消息列表
 * @returns
 */
export function getSystemMessageList(page: number, pageSize: number): Promise<Response<SystemMessageCenter>> {
  return PostRequest('/api/user/message/list', {
    type: 'system',
    page: page,
    pageSize: pageSize,
  })
}

/**
 * 获取系统消息列表
 * @returns
 */
export function getApplianceMessageDetailList(
  haId: string,
  page: number,
  pageSize: number
): Promise<Response<Message[]>> {
  return PostRequest('/api/user/message/' + haId + '/list', {
    type: 'system',
    page: page,
    pageSize: pageSize,
  })
}

/**
 * 阅读消息ID对应消息
 * @returns
 */
export function readByMessageid(messageId: number): Promise<Response<string>> {
  return PutRequest('/api/user/message/readByMessageid/' + messageId + '/read')
}

/**
 * 批量阅读haId对应消息
 * @returns
 */
export function readMessageByHaid(haId: string): Promise<Response<string>> {
  return PutRequest('/api/user/message/readByHaid/' + haId + '/read')
}
